/*
 * @lc app=leetcode.cn id=1464 lang=golang
 * @lcpr version=30119
 *
 * [1464] 数组中两元素的最大乘积
 */

// @lcpr-template-start
package main

import "fmt"

func main() {
	fmt.Println(maxProduct([]int{3, 4, 5, 2}))
}

// @lcpr-template-end
// @lc code=start
func maxProduct(nums []int) int {
	first, second := nums[0], nums[1]
	if first < second {
		first, second = second, first
	}
	for i := 2; i < len(nums); i++ {
		if nums[i] > first {
			second = first
			first = nums[i]
		} else if nums[i] > second {
			second = nums[i]
		}
	}
	return (first - 1) * (second - 1)
}

// @lc code=end

/*
// @lcpr case=start
// [3,4,5,2]\n
// @lcpr case=end

// @lcpr case=start
// [1,5,4,5]\n
// @lcpr case=end

// @lcpr case=start
// [3,7]\n
// @lcpr case=end

*/
